/*
 * logging.c
 *
 *  Created on: 26.05.2011
 *      Author: nick
 */

#include "logging.h"

//! write received data to buffer or SD-Card
void logData(char input)
{
	//TODO: Implement me!

	/*
	 * Format:
	 *
	 * Timestamp, Sensor Addresse, Wertetyp, Wert, Alarmflag NEWLINE
	 *
	 */

	//Receiverbuffer auslesen
}

int testWrite(void)
{
	//pic18 start
	FSFILE *pOldFile;
	FSFILE *pNewFile;
	char myData[20];
	char bfr [6];
	int bytesRead, bytesWritten;
	char newFile[] = "newfile.txt";
	char writeArg[] = "w";
	// Must initialize the FAT16/FAT32 library. It also initializes SPI and other related pins.
	if( !FSInit() )
		// Failed to initialize FAT16 � do something�
		return 1; // Card not present or wrong format
	// Create a new file
	pNewFile = FSfopen (newFile, writeArg);
	// Open an existing file to read
	pOldFile = FSfopen ("myfile.txt", "r");
	if ( pOldFile == NULL )
		// Either file is not present or card is not present
		return 1;

	// Read 10 bytes of data from the file.
	bytesRead = FSfread((void*)myData, 10, 1, pOldFile);
	// read bfrSize (5) items (of size 1 byte). returns items count
	bytesRead = FSfread( (void *)bfr, 1, bfrsize, pOldFile );
	// Write those fifteen bytes to the new file
	bytesWritten = FSfwrite ((void *) myData, 10, 1, pNewFile);
	bytesWritten = FSfwrite ((void *) bfr, 1, bfrsize, pNewFile);
	// After processing, close the file.
	FSfclose( pOldFile );
	FSfclose (pNewFile);
	//Delete the old file
	FSremove ("myfile.txt");
	//pic18 ende
	return 0;
}
